export default {
    name: 'bannerList',
    data() {
        return {
            listItem: [],
            Page: {
                total: 0,
                pageNum: 1,
                pageSize: 6
            },
            loading: false
        }
    },
    created() {
        this.btnAuthority = this.GLOBAL.powerAllBtn.banner;
        this.getData();
    },
    methods: {
        // 列表信息
        getData() {
            this.loading = true;
            this.$axios.post("/app/v1/platform/banner/list", {
                pagenum: this.Page.pageNum,
                pagesize: this.Page.pageSize
            }).then(res => {
                this.loading = false;
                if (res.data.code === 1) {
                    this.Page.total = parseInt(res.data.data.totalnum) || 0;
                    this.listItem = res.data.data.list;
                } else {
                    this.$message.warning("网络异常，数据获取失败，请重试！")
                }
            })
        },
        // 分页
        handleCurrentChange(val) {
            this.Page.pageNum = val;
            this.getData();
        },
        // 新增
        add() {
            this.$router.push({
                name: 'bannerAdd',
                params: {
                    manage: '新增',
                }
            });
            localStorage.removeItem('bannerData');
        },
        // 编辑
        edit(item) {
            // this.$store.commit("bannerStore/bannerList", item);
            localStorage.setItem("bannerData", JSON.stringify(item));
            this.$router.push({
                name: 'bannerAdd',
                params: {
                    manage: '编辑'
                }
            })
        },
        // 删除
        del(item) {
            let obj = {
                deleteid: [item.noticeid],
                type: '1'
            }
            this.$confirm('该操作将删除该banner, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$axios.post("/app/v1/platform/problem/delete", obj).then(resp => {
                    if (resp.data.code === 1) {
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        if (this.listItem.length === 1 && this.Page.pageNum > 1) {
                            this.Page.pageNum = this.Page.pageNum - 1
                        }
                        this.getData();
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'warning',
                    message: '已取消删除',
                    item: 6
                });
            });
        }
    },
    filters: {
        filtersCityname: function (val) {
            if (!val) {
                return '';
            } else if (val.indexOf(';') < 0){
                return val;
            } else {
                let newVal = val.replace(/;/g, '、');
                return newVal;
            }
        }
    }
}